<?php
namespace app\commission\model;

use app\BaseModel;
use think\facade\Db;

class Water extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_commission_water';

    protected $resultSetType = 'collection';


    /**
     * @author chenniang
     * @DataTime: 2020-04-21 14:45
     * @功能说明:领取
     */
    public function addWater($data){

        $data['create_time'] = time();

        $data['update_time'] = time();

        $res = $this->insert($data);

        return $res;
    }

    /**
     * @author chenniang
     * @DataTime: 2020-04-21 10:06
     * @功能说明:活动详情
     */
    public function waterInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():$data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-21 10:07
     * @功能说明:活动编辑
     */
    public function waterUpdate($dis,$data){

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @param $dis
     * @param $page
     * @功能说明:列表
     * @author chenniang
     * @DataTime: 2020-04-23 15:15
     */
    public function waterList($dis,$page){

        $data = $this->where($dis)->order('id desc')->paginate($page)->toArray();

        if(!empty($data['data'])){
            foreach ($data['data'] as &$v){
                //友好时间
                $f_time = datachange($v,'create_time');

                $v['create_time'] = $f_time['radar_group'].$f_time['radar_time'];

            }
        }

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-24 09:37
     * @功能说明:后台的流水记录
     */
    public function adminWaterList($dis,$mapor,$page){


        $data = $this->alias('a')
                ->join('longbing_card_reduction_pay_record b','a.order_id = b.id')
                ->join('longbing_card_user c','a.user_id = c.id','left')
                ->join('longbing_card_user_info d','a.user_id = d.fans_id','left')
                ->where($dis)
                ->where(function ($query) use ($mapor){
                    $query->whereOr($mapor);
                })
                ->field(['a.*','b.transaction_id','b.pay_price','c.nickName','d.name as staff_name',"from_unixtime(a.update_time,'%Y-%m-%d %H:%i:%s') as update_time"])
                ->group('a.id')
                ->order('a.id desc')
                ->paginate($page)
                ->toArray();

        return $data;
    }






}